from django_redis import get_redis_connection


class MyRedis:
    def __init__(self):
        self.cnnt = get_redis_connection('default')

    def setstr(self, key, value):
        self.cnnt.set(key, value)

    def settxt(self, key, value, ex):
        self.cnnt.setex(key, ex, value)

    def getstr(self, key):
        var = self.cnnt.get(key)
        if var:
            return var.decode('utf-8')
        else:
            return None

    def delstr(self, key):
        self.cnnt.delete(key)


myredis = MyRedis()
